/*
 * @(#)DmsDocumentIndex.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.dms.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.dcivision.dms.bean.DmsDocumentIndex;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;

/**
  DmsDocumentIndexDAObject.java

  This class is the data access bean for table "DMS_DOCUMENT_INDEX".

  @author      Roy Wong
  @company     DCIVision Limited
  @creation date   25/05/2004
  @version     $Revision: 1.11 $
*/

public class DmsDocumentIndexDAObject extends AbstractDAObject {

  public static final String REVISION = "$Revision: 1.11 $";

  public static final String TABLE_NAME = "DMS_DOCUMENT_INDEX";

  public DmsDocumentIndexDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }

  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("DOCUMENT_ID");
    //this.vecDBColumn.add("USER_DEFINED_FIELD_ID");
    this.vecDBColumn.add("INDEX_1");
    this.vecDBColumn.add("INDEX_2");
    this.vecDBColumn.add("INDEX_3");
    this.vecDBColumn.add("INDEX_4");
    this.vecDBColumn.add("INDEX_5");
    this.vecDBColumn.add("INDEX_6");
    this.vecDBColumn.add("INDEX_7");
    this.vecDBColumn.add("INDEX_8");
    this.vecDBColumn.add("INDEX_9");
    this.vecDBColumn.add("INDEX_10");
    this.vecDBColumn.add("INDEX_11");
    this.vecDBColumn.add("INDEX_12");
    this.vecDBColumn.add("INDEX_13");
    this.vecDBColumn.add("INDEX_14");
    this.vecDBColumn.add("INDEX_15");
    this.vecDBColumn.add("INDEX_16");
    this.vecDBColumn.add("INDEX_17");
    this.vecDBColumn.add("INDEX_18");
    this.vecDBColumn.add("INDEX_19");
    this.vecDBColumn.add("INDEX_20");
    this.vecDBColumn.add("INDEX_21");
    this.vecDBColumn.add("INDEX_22");
    this.vecDBColumn.add("INDEX_23");
    this.vecDBColumn.add("INDEX_24");
    this.vecDBColumn.add("INDEX_25");
    this.vecDBColumn.add("INDEX_26");
    this.vecDBColumn.add("INDEX_27");
    this.vecDBColumn.add("INDEX_28");
    this.vecDBColumn.add("INDEX_29");
    this.vecDBColumn.add("INDEX_30");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }

  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.USER_DEFINED_FIELD_ID,A.INDEX_1, A.INDEX_2, A.INDEX_3, A.INDEX_4, A.INDEX_5, A.INDEX_6, A.INDEX_7, A.INDEX_8, A.INDEX_9, A.INDEX_10, A.INDEX_11, A.INDEX_12, A.INDEX_13, A.INDEX_14, A.INDEX_15, ");
        sqlStat.append("A.INDEX_16, A.INDEX_17, A.INDEX_18, A.INDEX_19, A.INDEX_20, A.INDEX_21, A.INDEX_22, A.INDEX_23, A.INDEX_24, A.INDEX_25, A.INDEX_26, A.INDEX_27, A.INDEX_28, A.INDEX_29, A.INDEX_30, ");
        sqlStat.append("A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_DOCUMENT_INDEX A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          DmsDocumentIndex tmpDmsDocumentIndex = new DmsDocumentIndex();
          tmpDmsDocumentIndex.setID(getResultSetInteger(rs, "ID"));
          tmpDmsDocumentIndex.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsDocumentIndex.setUserDefinedFieldID(getResultSetInteger(rs, "USER_DEFINED_FIELD_ID"));
          tmpDmsDocumentIndex.setIndex1(getResultSetString(rs, "INDEX_1"));
          tmpDmsDocumentIndex.setIndex2(getResultSetString(rs, "INDEX_2"));
          tmpDmsDocumentIndex.setIndex3(getResultSetString(rs, "INDEX_3"));
          tmpDmsDocumentIndex.setIndex4(getResultSetString(rs, "INDEX_4"));
          tmpDmsDocumentIndex.setIndex5(getResultSetString(rs, "INDEX_5"));
          tmpDmsDocumentIndex.setIndex6(getResultSetString(rs, "INDEX_6"));
          tmpDmsDocumentIndex.setIndex7(getResultSetString(rs, "INDEX_7"));
          tmpDmsDocumentIndex.setIndex8(getResultSetString(rs, "INDEX_8"));
          tmpDmsDocumentIndex.setIndex9(getResultSetString(rs, "INDEX_9"));
          tmpDmsDocumentIndex.setIndex10(getResultSetString(rs, "INDEX_10"));
          tmpDmsDocumentIndex.setIndex11(getResultSetString(rs, "INDEX_11"));
          tmpDmsDocumentIndex.setIndex12(getResultSetString(rs, "INDEX_12"));
          tmpDmsDocumentIndex.setIndex13(getResultSetString(rs, "INDEX_13"));
          tmpDmsDocumentIndex.setIndex14(getResultSetString(rs, "INDEX_14"));
          tmpDmsDocumentIndex.setIndex15(getResultSetString(rs, "INDEX_15"));
          tmpDmsDocumentIndex.setIndex16(getResultSetString(rs, "INDEX_16"));
          tmpDmsDocumentIndex.setIndex17(getResultSetString(rs, "INDEX_17"));
          tmpDmsDocumentIndex.setIndex18(getResultSetString(rs, "INDEX_18"));
          tmpDmsDocumentIndex.setIndex19(getResultSetString(rs, "INDEX_19"));
          tmpDmsDocumentIndex.setIndex20(getResultSetString(rs, "INDEX_20"));
          tmpDmsDocumentIndex.setIndex21(getResultSetString(rs, "INDEX_21"));
          tmpDmsDocumentIndex.setIndex22(getResultSetString(rs, "INDEX_22"));
          tmpDmsDocumentIndex.setIndex23(getResultSetString(rs, "INDEX_23"));
          tmpDmsDocumentIndex.setIndex24(getResultSetString(rs, "INDEX_24"));
          tmpDmsDocumentIndex.setIndex25(getResultSetString(rs, "INDEX_25"));
          tmpDmsDocumentIndex.setIndex26(getResultSetString(rs, "INDEX_26"));
          tmpDmsDocumentIndex.setIndex27(getResultSetString(rs, "INDEX_27"));
          tmpDmsDocumentIndex.setIndex28(getResultSetString(rs, "INDEX_28"));
          tmpDmsDocumentIndex.setIndex29(getResultSetString(rs, "INDEX_29"));
          tmpDmsDocumentIndex.setIndex30(getResultSetString(rs, "INDEX_30"));
          tmpDmsDocumentIndex.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsDocumentIndex.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsDocumentIndex.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsDocumentIndex.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsDocumentIndex.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsDocumentIndex.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
          tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
          return(tmpDmsDocumentIndex);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
          
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.USER_DEFINED_FIELD_ID, A.INDEX_1, A.INDEX_2, A.INDEX_3, A.INDEX_4, A.INDEX_5, A.INDEX_6, A.INDEX_7, A.INDEX_8, A.INDEX_9, A.INDEX_10, A.INDEX_11, A.INDEX_12, A.INDEX_13, A.INDEX_14, A.INDEX_15, ");
        sqlStat.append("A.INDEX_16, A.INDEX_17, A.INDEX_18, A.INDEX_19, A.INDEX_20, A.INDEX_21, A.INDEX_22, A.INDEX_23, A.INDEX_24, A.INDEX_25, A.INDEX_26, A.INDEX_27, A.INDEX_28, A.INDEX_29, A.INDEX_30, ");
        sqlStat.append("A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_DOCUMENT_INDEX A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");

        // Form the WHERE clause for filtering.
        /*if (searchForm.isSearchable()) {
          String searchField = searchForm.getBasicSearchField();
          if (searchField.indexOf(".") < 0) {
            searchField = "A." + searchField;
          }
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }*/
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }

        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());

        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }

        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }

        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();

        this.positionCursor(rs, startOffset, pageSize);

        while (rs.next() && rowLoopCnt<pageSize) {
          DmsDocumentIndex tmpDmsDocumentIndex = new DmsDocumentIndex();
          tmpDmsDocumentIndex.setID(getResultSetInteger(rs, "ID"));
          tmpDmsDocumentIndex.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          
          tmpDmsDocumentIndex.setUserDefinedFieldID(getResultSetInteger(rs, " USER_DEFINED_FIELD_ID"));
          tmpDmsDocumentIndex.setIndex1(getResultSetString(rs, "INDEX_1"));
          tmpDmsDocumentIndex.setIndex2(getResultSetString(rs, "INDEX_2"));
          tmpDmsDocumentIndex.setIndex3(getResultSetString(rs, "INDEX_3"));
          tmpDmsDocumentIndex.setIndex4(getResultSetString(rs, "INDEX_4"));
          tmpDmsDocumentIndex.setIndex5(getResultSetString(rs, "INDEX_5"));
          tmpDmsDocumentIndex.setIndex6(getResultSetString(rs, "INDEX_6"));
          tmpDmsDocumentIndex.setIndex7(getResultSetString(rs, "INDEX_7"));
          tmpDmsDocumentIndex.setIndex8(getResultSetString(rs, "INDEX_8"));
          tmpDmsDocumentIndex.setIndex9(getResultSetString(rs, "INDEX_9"));
          tmpDmsDocumentIndex.setIndex10(getResultSetString(rs, "INDEX_10"));
          tmpDmsDocumentIndex.setIndex11(getResultSetString(rs, "INDEX_11"));
          tmpDmsDocumentIndex.setIndex12(getResultSetString(rs, "INDEX_12"));
          tmpDmsDocumentIndex.setIndex13(getResultSetString(rs, "INDEX_13"));
          tmpDmsDocumentIndex.setIndex14(getResultSetString(rs, "INDEX_14"));
          tmpDmsDocumentIndex.setIndex15(getResultSetString(rs, "INDEX_15"));
          tmpDmsDocumentIndex.setIndex16(getResultSetString(rs, "INDEX_16"));
          tmpDmsDocumentIndex.setIndex17(getResultSetString(rs, "INDEX_17"));
          tmpDmsDocumentIndex.setIndex18(getResultSetString(rs, "INDEX_18"));
          tmpDmsDocumentIndex.setIndex19(getResultSetString(rs, "INDEX_19"));
          tmpDmsDocumentIndex.setIndex20(getResultSetString(rs, "INDEX_20"));
          tmpDmsDocumentIndex.setIndex21(getResultSetString(rs, "INDEX_21"));
          tmpDmsDocumentIndex.setIndex22(getResultSetString(rs, "INDEX_22"));
          tmpDmsDocumentIndex.setIndex23(getResultSetString(rs, "INDEX_23"));
          tmpDmsDocumentIndex.setIndex24(getResultSetString(rs, "INDEX_24"));
          tmpDmsDocumentIndex.setIndex25(getResultSetString(rs, "INDEX_25"));
          tmpDmsDocumentIndex.setIndex26(getResultSetString(rs, "INDEX_26"));
          tmpDmsDocumentIndex.setIndex27(getResultSetString(rs, "INDEX_27"));
          tmpDmsDocumentIndex.setIndex28(getResultSetString(rs, "INDEX_28"));
          tmpDmsDocumentIndex.setIndex29(getResultSetString(rs, "INDEX_29"));
          tmpDmsDocumentIndex.setIndex30(getResultSetString(rs, "INDEX_30"));    
          tmpDmsDocumentIndex.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsDocumentIndex.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsDocumentIndex.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsDocumentIndex.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsDocumentIndex.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsDocumentIndex.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
          tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
          tmpDmsDocumentIndex.setRecordCount(totalNumOfRecord);
          tmpDmsDocumentIndex.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpDmsDocumentIndex);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }

  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.USER_DEFINED_FIELD_ID, A.INDEX_1, A.INDEX_2, A.INDEX_3, A.INDEX_4, A.INDEX_5, A.INDEX_6, A.INDEX_7, A.INDEX_8, A.INDEX_9, A.INDEX_10, A.INDEX_11, A.INDEX_12, A.INDEX_13, A.INDEX_14, A.INDEX_15, ");
        sqlStat.append("A.INDEX_16, A.INDEX_17, A.INDEX_18, A.INDEX_19, A.INDEX_20, A.INDEX_21, A.INDEX_22, A.INDEX_23, A.INDEX_24, A.INDEX_25, A.INDEX_26, A.INDEX_27, A.INDEX_28, A.INDEX_29, A.INDEX_30, ");
        sqlStat.append("A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_DOCUMENT_INDEX A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          DmsDocumentIndex tmpDmsDocumentIndex = new DmsDocumentIndex();
          tmpDmsDocumentIndex.setID(getResultSetInteger(rs, "ID"));
          tmpDmsDocumentIndex.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsDocumentIndex.setUserDefinedFieldID(getResultSetInteger(rs, "USER_DEFINED_FIELD_ID"));
          tmpDmsDocumentIndex.setIndex1(getResultSetString(rs, "INDEX_1"));
          tmpDmsDocumentIndex.setIndex2(getResultSetString(rs, "INDEX_2"));
          tmpDmsDocumentIndex.setIndex3(getResultSetString(rs, "INDEX_3"));
          tmpDmsDocumentIndex.setIndex4(getResultSetString(rs, "INDEX_4"));
          tmpDmsDocumentIndex.setIndex5(getResultSetString(rs, "INDEX_5"));
          tmpDmsDocumentIndex.setIndex6(getResultSetString(rs, "INDEX_6"));
          tmpDmsDocumentIndex.setIndex7(getResultSetString(rs, "INDEX_7"));
          tmpDmsDocumentIndex.setIndex8(getResultSetString(rs, "INDEX_8"));
          tmpDmsDocumentIndex.setIndex9(getResultSetString(rs, "INDEX_9"));
          tmpDmsDocumentIndex.setIndex10(getResultSetString(rs, "INDEX_10"));
          tmpDmsDocumentIndex.setIndex11(getResultSetString(rs, "INDEX_11"));
          tmpDmsDocumentIndex.setIndex12(getResultSetString(rs, "INDEX_12"));
          tmpDmsDocumentIndex.setIndex13(getResultSetString(rs, "INDEX_13"));
          tmpDmsDocumentIndex.setIndex14(getResultSetString(rs, "INDEX_14"));
          tmpDmsDocumentIndex.setIndex15(getResultSetString(rs, "INDEX_15"));
          tmpDmsDocumentIndex.setIndex16(getResultSetString(rs, "INDEX_16"));
          tmpDmsDocumentIndex.setIndex17(getResultSetString(rs, "INDEX_17"));
          tmpDmsDocumentIndex.setIndex18(getResultSetString(rs, "INDEX_18"));
          tmpDmsDocumentIndex.setIndex19(getResultSetString(rs, "INDEX_19"));
          tmpDmsDocumentIndex.setIndex20(getResultSetString(rs, "INDEX_20"));
          tmpDmsDocumentIndex.setIndex21(getResultSetString(rs, "INDEX_21"));
          tmpDmsDocumentIndex.setIndex22(getResultSetString(rs, "INDEX_22"));
          tmpDmsDocumentIndex.setIndex23(getResultSetString(rs, "INDEX_23"));
          tmpDmsDocumentIndex.setIndex24(getResultSetString(rs, "INDEX_24"));
          tmpDmsDocumentIndex.setIndex25(getResultSetString(rs, "INDEX_25"));
          tmpDmsDocumentIndex.setIndex26(getResultSetString(rs, "INDEX_26"));
          tmpDmsDocumentIndex.setIndex27(getResultSetString(rs, "INDEX_27"));
          tmpDmsDocumentIndex.setIndex28(getResultSetString(rs, "INDEX_28"));
          tmpDmsDocumentIndex.setIndex29(getResultSetString(rs, "INDEX_29"));
          tmpDmsDocumentIndex.setIndex30(getResultSetString(rs, "INDEX_30"));
          tmpDmsDocumentIndex.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsDocumentIndex.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsDocumentIndex.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsDocumentIndex.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsDocumentIndex.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsDocumentIndex.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
          tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
          result.add(tmpDmsDocumentIndex);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }

  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    DmsDocumentIndex tmpDmsDocumentIndex = (DmsDocumentIndex)((DmsDocumentIndex)obj).clone();

    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   DMS_DOCUMENT_INDEX(ID, DOCUMENT_ID,USER_DEFINED_FIELD_ID , INDEX_1, INDEX_2, INDEX_3, INDEX_4, INDEX_5, INDEX_6, INDEX_7, INDEX_8, INDEX_9, INDEX_10, INDEX_11, INDEX_12, INDEX_13, INDEX_14, INDEX_15, ");
        sqlStat.append("INDEX_16, INDEX_17, INDEX_18, INDEX_19, INDEX_20, INDEX_21, INDEX_22, INDEX_23, INDEX_24, INDEX_25, INDEX_26, INDEX_27, INDEX_28, INDEX_29, INDEX_30, ");
        sqlStat.append("RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2, tmpDmsDocumentIndex.getDocumentID());
        setPrepareStatement(preStat, 3, tmpDmsDocumentIndex.getUserDefinedFieldID());
        setPrepareStatement(preStat, 4, tmpDmsDocumentIndex.getIndex1());
        setPrepareStatement(preStat, 5, tmpDmsDocumentIndex.getIndex2());
        setPrepareStatement(preStat, 6, tmpDmsDocumentIndex.getIndex3());
        setPrepareStatement(preStat, 7, tmpDmsDocumentIndex.getIndex4());
        setPrepareStatement(preStat, 8, tmpDmsDocumentIndex.getIndex5());
        setPrepareStatement(preStat, 9, tmpDmsDocumentIndex.getIndex6());
        setPrepareStatement(preStat, 10, tmpDmsDocumentIndex.getIndex7());
        setPrepareStatement(preStat, 11, tmpDmsDocumentIndex.getIndex8());
        setPrepareStatement(preStat, 12, tmpDmsDocumentIndex.getIndex9());
        setPrepareStatement(preStat, 13, tmpDmsDocumentIndex.getIndex10());
        setPrepareStatement(preStat, 14, tmpDmsDocumentIndex.getIndex11());
        setPrepareStatement(preStat, 15, tmpDmsDocumentIndex.getIndex12());
        setPrepareStatement(preStat, 16, tmpDmsDocumentIndex.getIndex13());
        setPrepareStatement(preStat, 17, tmpDmsDocumentIndex.getIndex14());
        setPrepareStatement(preStat, 18, tmpDmsDocumentIndex.getIndex15());
        setPrepareStatement(preStat, 19, tmpDmsDocumentIndex.getIndex16());
        setPrepareStatement(preStat, 20, tmpDmsDocumentIndex.getIndex17());
        setPrepareStatement(preStat, 21, tmpDmsDocumentIndex.getIndex18());
        setPrepareStatement(preStat, 22, tmpDmsDocumentIndex.getIndex19());
        setPrepareStatement(preStat, 23, tmpDmsDocumentIndex.getIndex20());
        setPrepareStatement(preStat, 24, tmpDmsDocumentIndex.getIndex21());
        setPrepareStatement(preStat, 25, tmpDmsDocumentIndex.getIndex22());
        setPrepareStatement(preStat, 26, tmpDmsDocumentIndex.getIndex23());
        setPrepareStatement(preStat, 27, tmpDmsDocumentIndex.getIndex24());
        setPrepareStatement(preStat, 28, tmpDmsDocumentIndex.getIndex25());
        setPrepareStatement(preStat, 29, tmpDmsDocumentIndex.getIndex26());
        setPrepareStatement(preStat, 30, tmpDmsDocumentIndex.getIndex27());
        setPrepareStatement(preStat, 31, tmpDmsDocumentIndex.getIndex28());
        setPrepareStatement(preStat, 32, tmpDmsDocumentIndex.getIndex29());
        setPrepareStatement(preStat, 33, tmpDmsDocumentIndex.getIndex30());
        setPrepareStatement(preStat, 34, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 35, new Integer(0));
        setPrepareStatement(preStat, 36, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 37, currTime);
        setPrepareStatement(preStat, 38, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 39, currTime);
        preStat.executeUpdate();
        tmpDmsDocumentIndex.setID(nextID);
        tmpDmsDocumentIndex.setCreatorID(sessionContainer.getUserRecordID());
        tmpDmsDocumentIndex.setCreateDate(currTime);
        tmpDmsDocumentIndex.setUpdaterID(sessionContainer.getUserRecordID());
        tmpDmsDocumentIndex.setUpdateDate(currTime);
        tmpDmsDocumentIndex.setUpdateCount(new Integer(0));
        tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
        tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
        return(tmpDmsDocumentIndex);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    DmsDocumentIndex tmpDmsDocumentIndex = (DmsDocumentIndex)((DmsDocumentIndex)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE DMS_DOCUMENT_INDEX ");
        sqlStat.append("SET  DOCUMENT_ID=?, USER_DEFINED_FIELD_ID=?,INDEX_1=?, INDEX_2=?, INDEX_3=?, INDEX_4=?, INDEX_5=?, INDEX_6=?, INDEX_7=?, INDEX_8=?, INDEX_9=?, INDEX_10=?, INDEX_11=?, INDEX_12=?, INDEX_13=?, INDEX_14=?, INDEX_15=?, ");
        sqlStat.append("INDEX_16=?, INDEX_17=?, INDEX_18=?, INDEX_19=?, INDEX_20=?, INDEX_21=?, INDEX_22=?, INDEX_23=?, INDEX_24=?, INDEX_25=?, INDEX_26=?, INDEX_27=?, INDEX_28=?, INDEX_29=?, INDEX_30=?, ");
        sqlStat.append("UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpDmsDocumentIndex.getDocumentID());
        setPrepareStatement(preStat, 2, tmpDmsDocumentIndex.getUserDefinedFieldID());
        setPrepareStatement(preStat, 3, tmpDmsDocumentIndex.getIndex1());
        setPrepareStatement(preStat, 4, tmpDmsDocumentIndex.getIndex2());
        setPrepareStatement(preStat, 5, tmpDmsDocumentIndex.getIndex3());
        setPrepareStatement(preStat, 6, tmpDmsDocumentIndex.getIndex4());
        setPrepareStatement(preStat, 7, tmpDmsDocumentIndex.getIndex5());
        setPrepareStatement(preStat, 8, tmpDmsDocumentIndex.getIndex6());
        setPrepareStatement(preStat, 9, tmpDmsDocumentIndex.getIndex7());
        setPrepareStatement(preStat, 10, tmpDmsDocumentIndex.getIndex8());
        setPrepareStatement(preStat, 11, tmpDmsDocumentIndex.getIndex9());
        setPrepareStatement(preStat, 12, tmpDmsDocumentIndex.getIndex10());
        setPrepareStatement(preStat, 13, tmpDmsDocumentIndex.getIndex11());
        setPrepareStatement(preStat, 14, tmpDmsDocumentIndex.getIndex12());
        setPrepareStatement(preStat, 15, tmpDmsDocumentIndex.getIndex13());
        setPrepareStatement(preStat, 16, tmpDmsDocumentIndex.getIndex14());
        setPrepareStatement(preStat, 17, tmpDmsDocumentIndex.getIndex15());
        setPrepareStatement(preStat, 18, tmpDmsDocumentIndex.getIndex16());
        setPrepareStatement(preStat, 19, tmpDmsDocumentIndex.getIndex17());
        setPrepareStatement(preStat, 20, tmpDmsDocumentIndex.getIndex18());
        setPrepareStatement(preStat, 21, tmpDmsDocumentIndex.getIndex19());
        setPrepareStatement(preStat, 22, tmpDmsDocumentIndex.getIndex20());
        setPrepareStatement(preStat, 23, tmpDmsDocumentIndex.getIndex21());
        setPrepareStatement(preStat, 24, tmpDmsDocumentIndex.getIndex22());
        setPrepareStatement(preStat, 25, tmpDmsDocumentIndex.getIndex23());
        setPrepareStatement(preStat, 26, tmpDmsDocumentIndex.getIndex24());
        setPrepareStatement(preStat, 27, tmpDmsDocumentIndex.getIndex25());
        setPrepareStatement(preStat, 28, tmpDmsDocumentIndex.getIndex26());
        setPrepareStatement(preStat, 29, tmpDmsDocumentIndex.getIndex27());
        setPrepareStatement(preStat, 30, tmpDmsDocumentIndex.getIndex28());
        setPrepareStatement(preStat, 31, tmpDmsDocumentIndex.getIndex29());
        setPrepareStatement(preStat, 32, tmpDmsDocumentIndex.getIndex30());
        setPrepareStatement(preStat, 33, new Integer(tmpDmsDocumentIndex.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 34, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 35, currTime);
        setPrepareStatement(preStat, 36, tmpDmsDocumentIndex.getID());
        setPrepareStatement(preStat, 37, tmpDmsDocumentIndex.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpDmsDocumentIndex.setUpdaterID(sessionContainer.getUserRecordID());
          tmpDmsDocumentIndex.setUpdateDate(currTime);
          tmpDmsDocumentIndex.setUpdateCount(new Integer(tmpDmsDocumentIndex.getUpdateCount().intValue() + 1));
          tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
          tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
          return(tmpDmsDocumentIndex);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    DmsDocumentIndex tmpDmsDocumentIndex = (DmsDocumentIndex)((DmsDocumentIndex)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   DMS_DOCUMENT_INDEX ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpDmsDocumentIndex.getID());
        setPrepareStatement(preStat, 2, tmpDmsDocumentIndex.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpDmsDocumentIndex);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    DmsDocumentIndex tmpDmsDocumentIndex = (DmsDocumentIndex)this.oldValue;

    if (tmpDmsDocumentIndex != null) {
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getID()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getDocumentID()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUserDefinedFieldID()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex1()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex2()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex3()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex4()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex5()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex6()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex7()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex8()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex9()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex10()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex11()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex12()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex13()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex14()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex15()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex16()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex17()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex18()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex19()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex20()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex21()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex22()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex23()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex24()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex25()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex26()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex27()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex28()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex29()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex30()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUpdateDate()));
    }

    tmpDmsDocumentIndex = (DmsDocumentIndex)obj;
    if (tmpDmsDocumentIndex != null) {
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getID()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getDocumentID()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUserDefinedFieldID()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex1()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex2()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex3()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex4()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex5()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex6()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex7()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex8()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex9()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex10()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex11()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex12()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex13()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex14()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex15()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex16()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex17()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex18()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex19()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex20()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex21()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex22()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex23()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex24()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex25()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex26()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex27()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex28()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex29()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getIndex30()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpDmsDocumentIndex.getUpdateDate()));
    }

    auditTrailBase(opMode, oldValues, newValues);
  }

  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/

   /**
    * Gets the dms Document Index object by document ID.
    *  
    * @param documentID the document object ID
    * @return the abstract dms document object
    * @throws ApplicationException
    */
   public synchronized AbstractBaseObject getIndexByDocID(Integer documentID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.USER_DEFINED_FIELD_ID,A.INDEX_1, A.INDEX_2, A.INDEX_3, A.INDEX_4, A.INDEX_5, A.INDEX_6, A.INDEX_7, A.INDEX_8, A.INDEX_9, A.INDEX_10, A.INDEX_11, A.INDEX_12, A.INDEX_13, A.INDEX_14, A.INDEX_15, ");
        sqlStat.append("A.INDEX_16, A.INDEX_17, A.INDEX_18, A.INDEX_19, A.INDEX_20, A.INDEX_21, A.INDEX_22, A.INDEX_23, A.INDEX_24, A.INDEX_25, A.INDEX_26, A.INDEX_27, A.INDEX_28, A.INDEX_29, A.INDEX_30, ");
        sqlStat.append("A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_DOCUMENT_INDEX A ");
        sqlStat.append("WHERE  A.DOCUMENT_ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, documentID);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          DmsDocumentIndex tmpDmsDocumentIndex = new DmsDocumentIndex();
          tmpDmsDocumentIndex.setID(getResultSetInteger(rs, "ID"));
          tmpDmsDocumentIndex.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsDocumentIndex.setUserDefinedFieldID(getResultSetInteger(rs, "USER_DEFINED_FIELD_ID"));
          tmpDmsDocumentIndex.setIndex1(getResultSetString(rs, "INDEX_1"));
          tmpDmsDocumentIndex.setIndex2(getResultSetString(rs, "INDEX_2"));
          tmpDmsDocumentIndex.setIndex3(getResultSetString(rs, "INDEX_3"));
          tmpDmsDocumentIndex.setIndex4(getResultSetString(rs, "INDEX_4"));
          tmpDmsDocumentIndex.setIndex5(getResultSetString(rs, "INDEX_5"));
          tmpDmsDocumentIndex.setIndex6(getResultSetString(rs, "INDEX_6"));
          tmpDmsDocumentIndex.setIndex7(getResultSetString(rs, "INDEX_7"));
          tmpDmsDocumentIndex.setIndex8(getResultSetString(rs, "INDEX_8"));
          tmpDmsDocumentIndex.setIndex9(getResultSetString(rs, "INDEX_9"));
          tmpDmsDocumentIndex.setIndex10(getResultSetString(rs, "INDEX_10"));
          tmpDmsDocumentIndex.setIndex11(getResultSetString(rs, "INDEX_11"));
          tmpDmsDocumentIndex.setIndex12(getResultSetString(rs, "INDEX_12"));
          tmpDmsDocumentIndex.setIndex13(getResultSetString(rs, "INDEX_13"));
          tmpDmsDocumentIndex.setIndex14(getResultSetString(rs, "INDEX_14"));
          tmpDmsDocumentIndex.setIndex15(getResultSetString(rs, "INDEX_15"));
          tmpDmsDocumentIndex.setIndex16(getResultSetString(rs, "INDEX_16"));
          tmpDmsDocumentIndex.setIndex17(getResultSetString(rs, "INDEX_17"));
          tmpDmsDocumentIndex.setIndex18(getResultSetString(rs, "INDEX_18"));
          tmpDmsDocumentIndex.setIndex19(getResultSetString(rs, "INDEX_19"));
          tmpDmsDocumentIndex.setIndex20(getResultSetString(rs, "INDEX_20"));
          tmpDmsDocumentIndex.setIndex21(getResultSetString(rs, "INDEX_21"));
          tmpDmsDocumentIndex.setIndex22(getResultSetString(rs, "INDEX_22"));
          tmpDmsDocumentIndex.setIndex23(getResultSetString(rs, "INDEX_23"));
          tmpDmsDocumentIndex.setIndex24(getResultSetString(rs, "INDEX_24"));
          tmpDmsDocumentIndex.setIndex25(getResultSetString(rs, "INDEX_25"));
          tmpDmsDocumentIndex.setIndex26(getResultSetString(rs, "INDEX_26"));
          tmpDmsDocumentIndex.setIndex27(getResultSetString(rs, "INDEX_27"));
          tmpDmsDocumentIndex.setIndex28(getResultSetString(rs, "INDEX_28"));
          tmpDmsDocumentIndex.setIndex29(getResultSetString(rs, "INDEX_29"));
          tmpDmsDocumentIndex.setIndex30(getResultSetString(rs, "INDEX_30"));
          tmpDmsDocumentIndex.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsDocumentIndex.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsDocumentIndex.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsDocumentIndex.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsDocumentIndex.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsDocumentIndex.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
          tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
          return(tmpDmsDocumentIndex);
        } else {
          return null;
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
 
   
 /**
  * Update the document Index by the dms Document object
  * 
  * @param obj the abstract object of dmsDocument Index
  * @return abstract object of updated dmsDocumentIndex Object
  * @throws ApplicationException
  */
 public synchronized AbstractBaseObject updateByDocID(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    DmsDocumentIndex tmpDmsDocumentIndex = (DmsDocumentIndex)((DmsDocumentIndex)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE DMS_DOCUMENT_INDEX ");
        sqlStat.append("SET  DOCUMENT_ID=?, USER_DEFINED_FIELD_ID=?,INDEX_1=?, INDEX_2=?, INDEX_3=?, INDEX_4=?, INDEX_5=?, INDEX_6=?, INDEX_7=?, INDEX_8=?, INDEX_9=?, INDEX_10=?, INDEX_11=?, INDEX_12=?, INDEX_13=?, INDEX_14=?, INDEX_15=?, ");
        sqlStat.append("INDEX_16=?, INDEX_17=?, INDEX_18=?, INDEX_19=?, INDEX_20=?, INDEX_21=?, INDEX_22=?, INDEX_23=?, INDEX_24=?, INDEX_25=?, INDEX_26=?, INDEX_27=?, INDEX_28=?, INDEX_29=?, INDEX_30=?, ");
        sqlStat.append("UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  DOCUMENT_ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpDmsDocumentIndex.getDocumentID());
        setPrepareStatement(preStat, 2, tmpDmsDocumentIndex.getUserDefinedFieldID());
        setPrepareStatement(preStat, 3, tmpDmsDocumentIndex.getIndex1());
        setPrepareStatement(preStat, 4, tmpDmsDocumentIndex.getIndex2());
        setPrepareStatement(preStat, 5, tmpDmsDocumentIndex.getIndex3());
        setPrepareStatement(preStat, 6, tmpDmsDocumentIndex.getIndex4());
        setPrepareStatement(preStat, 7, tmpDmsDocumentIndex.getIndex5());
        setPrepareStatement(preStat, 8, tmpDmsDocumentIndex.getIndex6());
        setPrepareStatement(preStat, 9, tmpDmsDocumentIndex.getIndex7());
        setPrepareStatement(preStat, 10, tmpDmsDocumentIndex.getIndex8());
        setPrepareStatement(preStat, 11, tmpDmsDocumentIndex.getIndex9());
        setPrepareStatement(preStat, 12, tmpDmsDocumentIndex.getIndex10());
        setPrepareStatement(preStat, 13, tmpDmsDocumentIndex.getIndex11());
        setPrepareStatement(preStat, 14, tmpDmsDocumentIndex.getIndex12());
        setPrepareStatement(preStat, 15, tmpDmsDocumentIndex.getIndex13());
        setPrepareStatement(preStat, 16, tmpDmsDocumentIndex.getIndex14());
        setPrepareStatement(preStat, 17, tmpDmsDocumentIndex.getIndex15());
        setPrepareStatement(preStat, 18, tmpDmsDocumentIndex.getIndex16());
        setPrepareStatement(preStat, 19, tmpDmsDocumentIndex.getIndex17());
        setPrepareStatement(preStat, 20, tmpDmsDocumentIndex.getIndex18());
        setPrepareStatement(preStat, 21, tmpDmsDocumentIndex.getIndex19());
        setPrepareStatement(preStat, 22, tmpDmsDocumentIndex.getIndex20());
        setPrepareStatement(preStat, 23, tmpDmsDocumentIndex.getIndex21());
        setPrepareStatement(preStat, 24, tmpDmsDocumentIndex.getIndex22());
        setPrepareStatement(preStat, 25, tmpDmsDocumentIndex.getIndex23());
        setPrepareStatement(preStat, 26, tmpDmsDocumentIndex.getIndex24());
        setPrepareStatement(preStat, 27, tmpDmsDocumentIndex.getIndex25());
        setPrepareStatement(preStat, 28, tmpDmsDocumentIndex.getIndex26());
        setPrepareStatement(preStat, 29, tmpDmsDocumentIndex.getIndex27());
        setPrepareStatement(preStat, 30, tmpDmsDocumentIndex.getIndex28());
        setPrepareStatement(preStat, 31, tmpDmsDocumentIndex.getIndex29());
        setPrepareStatement(preStat, 32, tmpDmsDocumentIndex.getIndex30());
        setPrepareStatement(preStat, 33, new Integer(tmpDmsDocumentIndex.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 34, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 35, currTime);
        setPrepareStatement(preStat, 36, tmpDmsDocumentIndex.getDocumentID());
        setPrepareStatement(preStat, 37, tmpDmsDocumentIndex.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpDmsDocumentIndex.setUpdaterID(sessionContainer.getUserRecordID());
          tmpDmsDocumentIndex.setUpdateDate(currTime);
          tmpDmsDocumentIndex.setUpdateCount(new Integer(tmpDmsDocumentIndex.getUpdateCount().intValue() + 1));
          tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
          tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
          return(tmpDmsDocumentIndex);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
 /**
  * Delete the Document Detail by document ID
  * 
  * @param dmsDocumemntID the dmsDocument object ID
  * @throws ApplicationException
  */
  public synchronized void deleteByDocID(Integer dmsDocumemntID) throws ApplicationException {
    PreparedStatement preStat = null;
	    StringBuffer sqlStat = new StringBuffer();


    synchronized(dbConn) {
	    try {
	      int updateCnt = 0;
	      sqlStat.append("DELETE ");
	      sqlStat.append("FROM   DMS_DOCUMENT_INDEX ");
	      sqlStat.append("WHERE  DOCUMENT_ID=? ");
	      preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
	      setPrepareStatement(preStat, 1, dmsDocumemntID);
	  
	      updateCnt = preStat.executeUpdate();
	 
	    }catch (SQLException sqle) {
	      log.error(sqle, sqle);
	      throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
	    } catch (Exception e) {
	      log.error(e, e);
		      throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
	    } finally {
	      try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
	    }
	   }
  }
  
  /**
   * Update the DmsDocumentIndex's specfied field by update value and with user defined field and existing value specified.
   * 
   * @param targetField the field of dmsDocumentIndex that to be updated
   * @param newValue the update value to update to the specified field
   * @param cleanOptValue the exisiting value of the field
   * @param udfID the user defined field
   * @throws ApplicationException
   */
  public synchronized void cleanProfileIndexValue(String targetField, String newValue, String cleanOptValue, Integer udfID) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE DMS_DOCUMENT_INDEX ");
        sqlStat.append("SET  "+targetField+" = ");
        if (Utility.isEmpty(newValue)){
          sqlStat.append("NULL ");
        }else{
          sqlStat.append("? ");
        }
        sqlStat.append("WHERE  USER_DEFINED_FIELD_ID=?  AND "+targetField+" =? ");        
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        int i=1;
        if (!Utility.isEmpty(newValue)){
          setPrepareStatement(preStat, i++, newValue);
        }
        setPrepareStatement(preStat, i++, udfID);        
        setPrepareStatement(preStat, i++, cleanOptValue);

        updateCnt = preStat.executeUpdate();

        
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * Get all records by gived dms_document id List, and order by there's dms_document id.
   * @param lstDmsDocumentIds
   * @param recordStatus
   * @return
   * @throws ApplicationException
   */
  public synchronized List getList(List lstDmsDocumentIds, String recordStatus) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.USER_DEFINED_FIELD_ID, A.INDEX_1, A.INDEX_2, A.INDEX_3, A.INDEX_4, A.INDEX_5, A.INDEX_6, A.INDEX_7, A.INDEX_8, A.INDEX_9, A.INDEX_10, A.INDEX_11, A.INDEX_12, A.INDEX_13, A.INDEX_14, A.INDEX_15, ");
        sqlStat.append("A.INDEX_16, A.INDEX_17, A.INDEX_18, A.INDEX_19, A.INDEX_20, A.INDEX_21, A.INDEX_22, A.INDEX_23, A.INDEX_24, A.INDEX_25, A.INDEX_26, A.INDEX_27, A.INDEX_28, A.INDEX_29, A.INDEX_30, ");
        sqlStat.append("A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_DOCUMENT_INDEX A ");
        sqlStat.append("WHERE  A.DOCUMENT_ID IN (");
        for (int i=0; i<lstDmsDocumentIds.size(); i++) {
          sqlStat.append( (i==0?lstDmsDocumentIds.get(i):","+lstDmsDocumentIds.get(i)));
        }
        sqlStat.append(") ");
        if (recordStatus!=null) {
          sqlStat.append("AND  A.RECORD_STATUS=? ");
        }
        sqlStat.append("ORDER BY A.DOCUMENT_ID ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        if (recordStatus!=null) {
          this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        }
        rs = preStat.executeQuery();
        while (rs.next()) {
          DmsDocumentIndex tmpDmsDocumentIndex = new DmsDocumentIndex();
          tmpDmsDocumentIndex.setID(getResultSetInteger(rs, "ID"));
          tmpDmsDocumentIndex.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsDocumentIndex.setUserDefinedFieldID(getResultSetInteger(rs, "USER_DEFINED_FIELD_ID"));
          tmpDmsDocumentIndex.setIndex1(getResultSetString(rs, "INDEX_1"));
          tmpDmsDocumentIndex.setIndex2(getResultSetString(rs, "INDEX_2"));
          tmpDmsDocumentIndex.setIndex3(getResultSetString(rs, "INDEX_3"));
          tmpDmsDocumentIndex.setIndex4(getResultSetString(rs, "INDEX_4"));
          tmpDmsDocumentIndex.setIndex5(getResultSetString(rs, "INDEX_5"));
          tmpDmsDocumentIndex.setIndex6(getResultSetString(rs, "INDEX_6"));
          tmpDmsDocumentIndex.setIndex7(getResultSetString(rs, "INDEX_7"));
          tmpDmsDocumentIndex.setIndex8(getResultSetString(rs, "INDEX_8"));
          tmpDmsDocumentIndex.setIndex9(getResultSetString(rs, "INDEX_9"));
          tmpDmsDocumentIndex.setIndex10(getResultSetString(rs, "INDEX_10"));
          tmpDmsDocumentIndex.setIndex11(getResultSetString(rs, "INDEX_11"));
          tmpDmsDocumentIndex.setIndex12(getResultSetString(rs, "INDEX_12"));
          tmpDmsDocumentIndex.setIndex13(getResultSetString(rs, "INDEX_13"));
          tmpDmsDocumentIndex.setIndex14(getResultSetString(rs, "INDEX_14"));
          tmpDmsDocumentIndex.setIndex15(getResultSetString(rs, "INDEX_15"));
          tmpDmsDocumentIndex.setIndex16(getResultSetString(rs, "INDEX_16"));
          tmpDmsDocumentIndex.setIndex17(getResultSetString(rs, "INDEX_17"));
          tmpDmsDocumentIndex.setIndex18(getResultSetString(rs, "INDEX_18"));
          tmpDmsDocumentIndex.setIndex19(getResultSetString(rs, "INDEX_19"));
          tmpDmsDocumentIndex.setIndex20(getResultSetString(rs, "INDEX_20"));
          tmpDmsDocumentIndex.setIndex21(getResultSetString(rs, "INDEX_21"));
          tmpDmsDocumentIndex.setIndex22(getResultSetString(rs, "INDEX_22"));
          tmpDmsDocumentIndex.setIndex23(getResultSetString(rs, "INDEX_23"));
          tmpDmsDocumentIndex.setIndex24(getResultSetString(rs, "INDEX_24"));
          tmpDmsDocumentIndex.setIndex25(getResultSetString(rs, "INDEX_25"));
          tmpDmsDocumentIndex.setIndex26(getResultSetString(rs, "INDEX_26"));
          tmpDmsDocumentIndex.setIndex27(getResultSetString(rs, "INDEX_27"));
          tmpDmsDocumentIndex.setIndex28(getResultSetString(rs, "INDEX_28"));
          tmpDmsDocumentIndex.setIndex29(getResultSetString(rs, "INDEX_29"));
          tmpDmsDocumentIndex.setIndex30(getResultSetString(rs, "INDEX_30"));
          tmpDmsDocumentIndex.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsDocumentIndex.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsDocumentIndex.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsDocumentIndex.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsDocumentIndex.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsDocumentIndex.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsDocumentIndex.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getCreatorID()));
          tmpDmsDocumentIndex.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsDocumentIndex.getUpdaterID()));
          result.add(tmpDmsDocumentIndex);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
}
